<?php

class GongxianModel extends DBModel
{
	protected $_table = '{{gongxian}}';
	protected $_id = 'gid';
	
	public function getSumMuch($buserid)
	{
		$where['select'] = 'SUM(howmuch)';
		$where['condition'] = 'buserid = :buserid';
		$params[':buserid'] = $buserid;
		return $this->findScalar($where, $params);
	}
	
	public function getListByUserId($userid, $pageno, $pagesize)
	{
		$where['from'] = '{{gongxian}} g';
		$where['select'] = 'g.buserid,u.truename,u.sign,p.midpath logopath';
		$where['condition'] = 'g.userid = :userid';
		$where['join'] = 'left join {{user}} u on u.userid = g.buserid
						  left join {{photo}} p on u.logoid = p.photoid';
		$where['limit'] = $pagesize;
		$where['offset'] = max(0, $pageno - 1) * $pagesize;
		$params = array(':userid' => $userid);
		return $this->findAll($where, $params);
	}
	
	/*
	public function getListByBuserid($buserid)
	{
		$where['from'] = '{{gongxian}} g';
		$where['select'] = 'g.*,u.truename';
		$where['condition'] = 'g.buserid = :buserid';
		$where['join'] = 'left join {{user}} u on u.userid = g.userid';
		$params = array(':buserid' => $buserid);
		return $this->findAll($where, $params);
	}
	*/
}